package com.starblink.wishlist.detailsadd.ui.cell

import android.graphics.drawable.AnimationDrawable
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.*
import com.starblink.android.basic.util.bus.FlowBus
import com.starblink.android.basic.util.bus.FlowConst
import com.starblink.basic.ext.load
import com.starblink.basic.style.R
import com.starblink.basic.style.databinding.EmptyViewWishFilterBinding
import com.starblink.basic.util.CommUtils
import com.starblink.wishlist.databinding.ItemDetailsAddBinding
import com.starblink.wishlist.wishallitems.ui.bean.RvNormalEmpty
import com.starblink.wishlist.wishlistdetails.ui.bean.RvBoardDetailsItemEntry


/**
 * feeds无数据
 */
class EmptyWishListAddCell(
    binding: EmptyViewWishFilterBinding
) :
    BaseBindingVH<RvNormalEmpty, EmptyViewWishFilterBinding>(binding) {


    init {
        itemView.layoutParams = StaggeredGridLayoutManager.LayoutParams(
            StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT,
            StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT
        ).apply {
            isFullSpan = true
        }
    }

    override fun onBind(model: RvNormalEmpty, position: Int) {
        binding.marginLayoutTop.margin(topMargin = 72.dp)
        binding.msgSub.text = "No matching items found"

    }
}


class WishlistAddCell(
    binding: ItemDetailsAddBinding,
    private val itemClick: () -> Unit
) :
    BaseBindingVH<RvBoardDetailsItemEntry, ItemDetailsAddBinding>(binding) {


    override fun onBind(model: RvBoardDetailsItemEntry, position: Int) {
        binding.mainImg.load(model.wishItem.mainImg)

        if (model.wishItem.valid == true) {
            binding.mainImgInvalid.gone()
        } else {
            binding.mainImgInvalid.visible()
        }

        if (model.wishItem.specifiedWishListCollected == true) {
            binding.mainImgLayer.visible()
            binding.mainImgSelect.setImageDrawable(CommUtils.getDrawable(com.starblink.wishlist.R.drawable.ic_checkbox_x))
        } else {
            binding.mainImgLayer.gone()
            if (model.hasChoice) {
                binding.mainImgSelect.setImageDrawable(CommUtils.getDrawable(R.drawable.ic_checkbox_true))
            } else {
                binding.mainImgSelect.setImageDrawable(CommUtils.getDrawable(com.starblink.wishlist.R.drawable.ic_checkbox_z))
            }
        }

        binding.addLay.click {
            if (model.wishItem.specifiedWishListCollected == true) {
                return@click
            }
            if (model.hasChoice) {
                model.hasChoice = false
                binding.mainImgSelect.setImageDrawable(CommUtils.getDrawable(com.starblink.wishlist.R.drawable.ic_checkbox_z))
            } else {
                model.hasChoice = true
                binding.mainImgSelect.setImageDrawable(CommUtils.getDrawable(R.drawable.ic_checkbox_true))
            }
            itemClick.invoke()
        }
    }
}










